package com.csair.seam.controller.pc;

import com.csair.seam.domain.model.entity.IdleShow;
import com.csair.seam.domain.service.IdleShowService;
import com.csair.seam.infrastructure.log.LogOperation;
import com.csair.seam.infrastructure.web.BaseController;
import com.csair.seam.infrastructure.web.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Api(tags = "设备共享")
@RestController
@RequestMapping("/pc/idle/show")
public class IdleShowContrlloer extends BaseController {

    @Autowired
    private IdleShowService idleShowService;


    /**
     * 数据验证，提取成一个aop切面验证数据
     * aop类：com.csair.seam.infrastructure.log.IdleShowAspect
     * aop方法：com.csair.seam.infrastructure.log.IdleShowAspect.validateIdleShow
     * aop通知类型：环绕通知
     * @param idleShow
     * @param result
     * @param files
     * @return
     */
    @ApiOperation(value = "/验证idleShow数据", notes = "validateIdleShow",httpMethod="POST")
    @RequestMapping("/validateIdleShow")
    @LogOperation(bizName = "验证idleShow数据")
    public BaseResponse<String> validateIdleShow(@ApiParam(value="设备信息",required = true) @Validated IdleShow idleShow,
                                                 BindingResult result,
                                                 @ApiParam(value="图片") MultipartFile[] files){

        return buildSuccess("true");
    }

    /**
     * 添加有编码设备，提取成一个aop切面验证数据
     * aop类：com.csair.seam.infrastructure.log.IdleShowAspect
     * aop方法：com.csair.seam.infrastructure.log.IdleShowAspect.validateIdleShowzx
     * aop通知类型：环绕通知
     * @param idleShow
     * @param result
     * @param files
     * @return
     */

    @ApiOperation(value = "/添加idleShow数据", notes = "insertIdleShow",httpMethod="POST")
    @RequestMapping("/insertIdleShow")
    @LogOperation(bizName = "添加idleShow数据")
    public Object insertIdleShow(@ApiParam(value="设备信息",required = true) @Validated IdleShow idleShow,
                                 BindingResult result,
                                 @ApiParam(value="图片") MultipartFile[] files){

        List<String> errorMeeage = idleShow.checkIdleShow();
        if(!errorMeeage.isEmpty()){
            return buildError(errorMeeage.toString(),"");
        }
        int i  = idleShowService.inserIdleShow(idleShow.getEquipCodeList());
        if(i < 0){
            return buildError("保存异常","");
        }
        return buildSuccess(idleShow.getShowCode());
    }


    @ApiOperation(value = "/获取idleShow数据", notes = "获取idleShow数据",httpMethod="POST")
    @RequestMapping("/findIdleShow")
    @LogOperation(bizName = "获取idleShow数据")
    public Object findIdleShow(IdleShow idleShow){
        List<IdleShow> iss = idleShowService.findIdleShow(idleShow);
        return null;
    }
}
